package vg.modules.attribute_panel.components.data;

import java.awt.Color;

/**
 * This class realizes storage for shower of attribute table.
 * @author tzolotuhin
 */
public class AttributeShower implements Comparable<AttributeShower>{
	public final static int DEF_SHOW_YELLOW = 3;
	public final static int DEF_SHOW_GREEN = 1;
	public final static int DEF_UNSHOW_GREEN = 0;
	public final static int DEF_UNSHOW_YELLOW = 2;
	private int show;
	private Color color;
	/**
	 * Constructor.
	 * show - use DEF_SHOW_YELLOW, DEF_SHOW_GREEN, DEF_UNSHOW_GREEN and DEF_UNSHOW_YELLOW constants for it.
	 */
	public AttributeShower(final int show) {
		this.show = show;
		findColor();
	}
	public synchronized void setYellowShow() {
		this.show = DEF_SHOW_YELLOW;
		this.color = Color.YELLOW;
	}
	public synchronized void setGreenShow() {
		this.show = DEF_SHOW_GREEN;
		this.color = Color.GREEN;
	}
	public synchronized void setYellowUnShow() {
		this.show = DEF_UNSHOW_YELLOW;
		this.color = Color.YELLOW;
	}
	public synchronized void setGreenUnShow() {
		this.show = DEF_UNSHOW_GREEN;
		this.color = Color.GREEN;
	}
	public final Color getColor() {
		return(this.color);
	}
	public final int getShow() {
		return(this.show);
	}
	public synchronized boolean isShow() {
		if(this.show == DEF_SHOW_GREEN || this.show == DEF_SHOW_YELLOW)
			return(true);
		return(false);
	}
	public synchronized void show() {
		if(this.show == DEF_UNSHOW_GREEN) this.show = DEF_SHOW_GREEN;
		if(this.show == DEF_UNSHOW_YELLOW) this.show = DEF_SHOW_YELLOW;
		findColor();
	}
	public synchronized void unshow() {
		if(this.show == DEF_SHOW_GREEN) this.show = DEF_UNSHOW_GREEN;
		if(this.show == DEF_SHOW_YELLOW) this.show = DEF_UNSHOW_YELLOW;
		findColor();
	}
	///////////////////////////////////////////////////////////////////////////
	// IMPLEMETATION OF COMPARABLE
	///////////////////////////////////////////////////////////////////////////
	public int compareTo(AttributeShower o) {
		if(o.isShow() && !this.isShow()) {
			return(-1);
		}
		if(!o.isShow() && this.isShow()) {
			return(1);
		}
		return(0);
	};
	///////////////////////////////////////////////////////////////////////////
	// PRIVATE METHODS
	///////////////////////////////////////////////////////////////////////////
	private void findColor() {
		switch(this.show) {
			case DEF_SHOW_GREEN:this.color = Color.GREEN;break;
			case DEF_SHOW_YELLOW:this.color = Color.YELLOW;break;
			case DEF_UNSHOW_GREEN:this.color = Color.GREEN;break;
			case DEF_UNSHOW_YELLOW:this.color = Color.YELLOW;break;
			default: this.color = Color.BLUE;
		}
	}
}
